package me.zhengjie.inter.rest;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import me.zhengjie.annotation.rest.RepeatSubmit;
import me.zhengjie.business.domain.Order;
import me.zhengjie.business.domain.vo.OrderWxVo;
import me.zhengjie.business.service.AdlXmxxService;
import me.zhengjie.business.service.OrderService;
import me.zhengjie.business.service.dto.OrderDto;
import me.zhengjie.business.service.dto.OrderQueryCriteria;
import me.zhengjie.utils.PageUtil;
import me.zhengjie.utils.SecurityUtils;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * @author xiahongbo
 * @date 2022-07-10
 **/
@RestController
@RequiredArgsConstructor
@Api(tags = "移动端订单")
@RequestMapping("/mp/order")
public class MpOrderController {

    private final OrderService orderService;

    @GetMapping(value = "/listDisability")
    @ApiOperation("订单列表-患者端")
    public ResponseEntity<Object> listDisability(OrderQueryCriteria criteria, Pageable pageable) {
        Page<Order> list = orderService.listDisability(criteria,pageable);
        return new ResponseEntity<>(PageUtil.toMpContent(list), HttpStatus.OK);
    }

    @GetMapping(value = "/listCaregiver")
    @ApiOperation("订单列表-执行人员")
    public ResponseEntity<Object> listCaregiver(OrderQueryCriteria criteria, Pageable pageable) {
        long userId = SecurityUtils.getCurrentUserId();
        criteria.setBisOrderHlyId(userId);
        //    Page<Order> page = orderService.queryAll(criteria,pageable);
    //    Page<OrderWxVo> page = orderService.queryAllOrderWxVoList(criteria, pageable);

        int[] startEnd = PageUtil.transToStartEnd(pageable.getPageNumber(), pageable.getPageSize());
               Object page = orderService.queryAllOrderWxVoList(criteria, startEnd, pageable);
        return new ResponseEntity<>(PageUtil.toMpContent(page), HttpStatus.OK);
    }

    @GetMapping(value = "/aCaregiver")
    @ApiOperation("订单列表-执行人员")
    public ResponseEntity<Object> aCaregiver(OrderQueryCriteria criteria, Pageable pageable) {
        Object page = orderService.findById(criteria.getBisOrderId());
        return new ResponseEntity<>(PageUtil.toMpContent(page), HttpStatus.OK);
    }

    @PostMapping(value = "/execute")
    @ApiOperation("执行订单")
    @RepeatSubmit
    public ResponseEntity<Object> execute(@Validated @RequestBody Order resources) {
        orderService.updateZt(resources);
        return new ResponseEntity<>(PageUtil.toMpContent(1), HttpStatus.OK);
    }

    @GetMapping(value = "/queryVerifyPersonCnt")
    @ApiOperation("订单列表-执行人员")
    public ResponseEntity<Object> queryVerifyPersonCnt(OrderQueryCriteria criteria) {
        Integer cnt = orderService.queryVerifyPerson(criteria.getBisOrderId());
        return new ResponseEntity<>(PageUtil.toMpContent(cnt), HttpStatus.OK);
    }
}
